Question: 1 -
Which of the following gets called when an object is being created?
-
Destructors
-
Constuctor
-
Main
-
Virtual Function
Answer:
Constuctor
Solution:
Virtual Function gets called when an object is being created.
Virtual Function gets called when an object is being created.
Question: 2 -
State whether the following statements about the constructor are True or False. i) constructors should be declared in the private section. ii) constructors are invoked automatically when the objects are created.
-
False,False
-
True,False
-
True,True
-
False,True
Answer:
False,True
Solution:
Statement 1 is false and statement 2 is true.
Statement 1 is false and statement 2 is true.
Question: 3 -
Which of the followings is/are automatically added to every class, if we do not write our own.
-
All of the above
-
Assignment Operator
-
A constructor without any parameter
-
Copy Constructor
Answer:
All of the above
Solution:
In C++, if we do not write our own, then compiler automatically creates a default constructor, a copy constructor and a assignment operator for every class.
In C++, if we do not write our own, then compiler automatically creates a default constructor, a copy constructor and a assignment operator for every class.
Question: 4 -
Destructor has a same name as the constructor and it is preceded by?
-
?
-
~
-
$
-
!
Answer:
~
Solution:
Destructor has a same name as the constructor and it is preceded by ~.
Destructor has a same name as the constructor and it is preceded by ~.
Question: 5 -
Like constructors, can there be more than one destructors in a class?
-
Can't Say
-
May Be
-
No
-
Yes
Answer:
No
Solution:
There can be only one destructor in a class. Destructor's signature is always ~ClassNam()and they can not be passed arguments.
There can be only one destructor in a class. Destructor's signature is always ~ClassNam()and they can not be passed arguments.